
package com.joolun.cloud.weixin.admin.controller;

import com.joolun.cloud.common.core.util.R;
import com.joolun.cloud.common.security.annotation.Inside;
import com.joolun.cloud.weixin.admin.config.ma.WxMaConfiguration;
import com.joolun.cloud.weixin.admin.config.mp.WxMpConfiguration;
import com.joolun.cloud.weixin.common.dto.MaQrCodeDTO;
import com.joolun.cloud.weixin.common.dto.WxJsApiDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileInputStream;
import java.util.Base64;

/**
 * jssdk
 *
 * @author www.joolun.com
 * @date 2019-10-25 15:39:39
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/wxjssdk")
@Api(value = "wxjssdk", tags = "jssdkAPI")
public class WxJsSdkController {

	/**
	 * 获取jssdk config参数
	 * @param wxJsApiDTO
	 * @return
	 */
	@ApiOperation(value = "获取jssdk config参数")
	@PostMapping("/config")
	@Inside
	public R createJsapiSignature(@RequestBody WxJsApiDTO wxJsApiDTO){
		try {
			return R.ok(WxMpConfiguration.getMpService(wxJsApiDTO.getAppId()).createJsapiSignature(wxJsApiDTO.getUrl()));
		} catch (Exception e) {
			e.printStackTrace();
			return R.failed(e.getMessage());
		}
	}
}
